package com.example.myapplication;

import android.view.View;
import android.widget.Button;
import com.app.networklibrary.config.NetworkConfig;
import com.app.networklibrary.model.MessageInfo;
import com.app.networklibrary.retrofitUtils.AllRequestAppliction;
import com.app.toolboxlibrary.FastJsonUtils;
import com.app.toolboxlibrary.LogUtil;
import com.app.xxbusiness.base.AllBaseUIActivity;
import com.app.xxbusiness.base.XxBusinessConfig;

public class TestActivity extends AllBaseUIActivity {
    private Button testBt;

    @Override
    protected void init() {
        testBt = findViewById(R.id.test_bt);
        testBt.setOnClickListener(this);
    }

    @Override
    protected void initBundleData() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.act_test_layout;
    }

    @Override
    public void doClick(View view) {
        super.doClick(view);
        if(view == testBt){
            checkNeed() ;
        }
    }


    //app更新接口（这是例子）
    public void doClientUpdate() {
        needLoadRequest(AllRequestAppliction.check4Update,
                new MessageInfo("version", NetworkConfig.APPCODE),
                new MessageInfo("os", "android")
        );
    }

    //权限校验
    protected void checkNeed() {
        initPermissionUtils(XxBusinessConfig.APPNEEDPERMISSION);
        permissionUtils.checkUsePermission(this, permissionUtils.ALBUM);
    }
    //授权结束，同意
    @Override
    public void afterPermissionOpen(int openRequestCode) {
        super.afterPermissionOpen(openRequestCode);
        switch (openRequestCode) {
            case XxBusinessConfig.APPNEEDPERMISSION:
                doClientUpdate();
                break;
        }

    }

    //不同意自行处理
    @Override
    public void afterPermissionClose(int openRequestCode) {
        super.afterPermissionClose(openRequestCode);
        switch (openRequestCode) {
            case XxBusinessConfig.APPNEEDPERMISSION:
                break;
        }
    }

    @Override
    public void doAfterRequestSuccess(String application, String resultData) {
        super.doAfterRequestSuccess(application, resultData);
        LogUtil.showLog(resultData);
        if(AllRequestAppliction.check4Update.equals(application)){
            UpdateInfo updateInfo = (UpdateInfo) FastJsonUtils.jsonToBean(resultData,UpdateInfo.class);
            if(null != updateInfo){
                initAppApkUpdateUtil("testDemo",updateInfo.getUpdateUrl(),updateInfo.isForceUpdate());
            }
        }
    }
}
